﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP20.ViewModels
{
    public class ST13DeviceManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST13DeviceManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            InitParam();
            ////开启定时器任务
            //DispatcherTimer dispatcherTimer = new DispatcherTimer();
            //dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            //dispatcherTimer.Tick += OnTick;
            //dispatcherTimer.Start();
        }

        //private void OnTick(object? sender, EventArgs e)
        //{
        //    ST13PressureCurrentValue = OtherDevicePLCToPC_Global.testData2s[2].CurrentValue;
        //    ST13PressureResult = OtherDevicePLCToPC_Global.testData2s[2].Result[0];
        //    ST13HeightCurrentValue = OtherDevicePLCToPC_Global.testDatas[2].CurrentValue;
        //    ST13HeightResultValue = OtherDevicePLCToPC_Global.testDatas[2].ResultValue;
        //    ST13HeightResult = OtherDevicePLCToPC_Global.testDatas[2].Result[0];
        //    ST13ODCurrentValue = OtherDevicePLCToPC_Global.ODAndTemp[0];
        //    ST13ODResultValue = OtherDevicePLCToPC_Global.ODAndTemp[1];
        //}

        private void InitParam()
        {
            ST13HoldingTime = TestPressure_Global.testPressures[2].HoldingTime;
            ST13HoldingPressure = SetPressure_Global.pressures[2];
            ST13HeightSettingTime = TestHigh_Global.testValues[2].SettingTime;
        }



        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST13");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST13View, param);
        }


        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {
                case "ST13HoldingTime":
                    TestPressure_Global.testPressures[2].HoldingTime = ST13HoldingTime;
                    break;
                case "ST13HoldingPressure":
                    SetPressure_Global.pressures[2] = ST13HoldingPressure;
                    break;
                case "ST13HeightSettingTime":
                    TestHigh_Global.testValues[2].SettingTime = ST13HeightSettingTime;
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region 属性
        private short _ST13HoldingTime;
        public short ST13HoldingTime
        {
            get { return _ST13HoldingTime; }
            set { SetProperty(ref _ST13HoldingTime, value); }
        }

        private float _ST13HoldingPressure;
        public float ST13HoldingPressure
        {
            get { return _ST13HoldingPressure; }
            set { SetProperty(ref _ST13HoldingPressure, value); }
        }
        private short _ST13HeightSettingTime;
        public short ST13HeightSettingTime
        {
            get { return _ST13HeightSettingTime; }
            set { SetProperty(ref _ST13HeightSettingTime, value); }
        }


        #endregion
    }
}
